package citylist

import (
	"go-reptile/crawler/engine"
	"regexp"
)

var profileRe = regexp.MustCompile(`<a href="(http://album.zhenai.com/u/[0-9]+)"[^>]*>([^<]+)</a>`)
var cityUrlRe = regexp.MustCompile(`href="(http://www.zhenai.com/zhenghun/[^"]+)"`)

func ParserCity(contents []byte,_ string) engine.ParserResult{

	matches := profileRe.FindAllSubmatch(contents, -1)

	result := engine.ParserResult{}

	for _,m := range matches {
		url := string(m[1])
		result.Requests = append(result.Requests, engine.Request{
			Url:					url,
			ParserFunc: ProfileParser(string(m[2])),
		})
	}

	matches1 := cityUrlRe.FindAllSubmatch(contents,-1)
	for _,m := range matches1{
		result.Requests = append(result.Requests,
			engine.Request{
			Url:					string(m[1]),
			ParserFunc:	ParserCity,
		})
	}
	return result
}
